package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-10-13 12:54
 **/
public class LeetCode48 {
    //matrix是矩阵的意思,rotate是旋转的意思
    /*public void rotate(int[][] matrix) {
        int n = matrix.length;
        int[][] matrixTemp = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int i1 = 0; i1 < n; i1++) {
                matrixTemp[i1][n - i - 1] = matrix[i][i1];
            }
        }

        for (int i = 0; i < matrixTemp.length; i++) {
            for (int i1 = 0; i1 < matrixTemp[i].length; i1++) {
                matrix[i][i1] = matrixTemp[i][i1];
            }
        }
    }*/

    public void rotate(int[][] matrix) {
        int n = matrix.length;
        for (int i = 0; i < n / 2; i++) {
            for (int i1 = 0; i1 < n; i1++) {
                int temp = matrix[i][i1];
                matrix[i][i1] = matrix[n - i - 1][i1];
                matrix[n - i - 1][i1] = temp;
            }
        }

        for (int i = 0; i < matrix.length; i++) {
            for (int i1 = 0; i1 < i; i1++) {
                int temp = matrix[i][i1];
                matrix[i][i1] = matrix[i1][i];
                matrix[i1][i] = temp;
            }
        }
    }

}
